package sma.interf;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sma.nasa.NasaTool;

public class SyncCalculateImpl extends UnicastRemoteObject implements ICalculateIss {

	/** */
	private static final long serialVersionUID = 1L;

	/** Logger for this class. */
	protected final static Logger LOGGER = LoggerFactory.getLogger(SyncCalculateImpl.class);

	public SyncCalculateImpl() throws RemoteException {
		super();
	}

	private int nbCalc = 0;

	public double[] evaluateSingleState(double[] input) throws RemoteException {
		double[] result = null;
		try {
			result = NasaTool.checker.evaluateSingleState(input);
			nbCalc++;
			if (nbCalc % 50 == 0) {
				LOGGER.info("nb calcul done {}", nbCalc);
			}
		} catch (Exception e) {
			LOGGER.error("Problem", e);
			// throw new RemoteException("", e);
		}
		return result;
	}

	public double[][] evaluateMutipleState(double[][] input) throws RemoteException {
		int nb = input.length;
		double[][] resultArray = new double[nb][];
		for (int i = 0; i < resultArray.length; i++) {
			resultArray[i] = this.evaluateSingleState(input[i]);
		}
		return resultArray;
	}

	public String getHostName() throws RemoteException {
		return BindUtil.HOST_NAME;
	}

}
